
import javax.servlet.http.*;
import java.sql.*;
import java.io.*;

public class MessageServlet extends HttpServlet
{
  
  public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException
  {

     try
       {

       String student_id=request.getParameter("student_id");
 
String college_code=request.getParameter("college_code");
String message=request.getParameter("message");


         response.setContentType("text/html");

         PrintWriter out=response.getWriter();
        

           Class.forName("oracle.jdbc.driver.OracleDriver");
         Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","pac","mca"); 
         Statement stmt=con.createStatement();  
ResultSet rs = stmt.executeQuery("SELECT *FROM student_register WHERE student_id='"+student_id+"'");
  if(rs.next())

  {
         PreparedStatement pstmt1=con.prepareStatement("insert into message_stu (student_id,college_code,message) values(?,?,?)");
         
        pstmt1.setString(1,student_id);
        pstmt1.setString(2,college_code);
         pstmt1.setString(3,message);
         pstmt1.executeUpdate();
  out.println("<html>");
     
         out.println("<body background=\"t11.jpg\">");
 
         out.println(" <font size=\"4\"> ");
  
         out.println("<br> <b>send Successfully </b>");

         out.println("<br><br> <b> <a href=\"company-login.html\"> <font color=\"blue\"> Click here </font> </a> to Login </b>");

         out.println("</font>");

         out.println("</body>");

         out.println("</html>");   

 }
  else
  {
    out.println("The student id does not existed,<br><br>student must be  registerd");
  }
     }
 
    catch(Exception e)
       {
         response.sendError(505,e.getMessage());
         e.printStackTrace();
       }    

  }

}  

 